%Time_interval is the last day we simulate price.
%discount_factor is the vector B(0,t) from t = 0 to time_interval( = end_day*time_step).
%The formula is B(0,t) = (1+r_0(t))^(-t/365)

%risk_free is delta_t * f_0(t,t+delta_t) with t begin from 0 to time_interval.
%delta_t = time_step/365 years
%The formula is delta_t * f_0(t,t+delta_t) =  B(0,t) / B(0,t+delta_t) - 1
%%
function [discount_factor risk_free] = estimateRiskFree(maturity_array, zero_coupon_rate,time_step,end_day)
    
    %Interpolate zero_coupon rate
    zc_rate = interp1(maturity_array,zero_coupon_rate,(0:end_day)*time_step,'spline','extrap')/10000;
    %Calculate vector B(0,t)
    discount_factor = (1+zc_rate(1:end)).^(-(0:end_day)*time_step/365);
    %Calculate delta_t * f_0(t,t+delta_t)
    risk_free = discount_factor(1:end-1)./discount_factor(2:end) - 1;
